﻿using System;
using Group3.MediaTool.OWIN;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net.Http;

namespace Group3.MediaTool.UnitTests
{
    [TestClass]
    public class OWINTest
    {
        [TestMethod]
        public void StartWebServiceAndClientCall()
        {
            using (WebService.Start()) //Starts the webservice
            {
                //Part in the using-block is relevant for the call.
                //After the WebService is started, an application can call the specified Controller.
                //Controllers are specified in the WebService-Project
                string baseAddress = "http://localhost:9000/";
                try
                {
                    HttpClient client = new HttpClient(); //Makes the ClientCall
                    var response = client.GetAsync(baseAddress + "api/default").Result;
                    string value = response.Content.ReadAsStringAsync().Result;
                    if (String.IsNullOrWhiteSpace(value))
                        Assert.Fail();
                    if (!value.Contains("value1"))
                        Assert.Fail();
                }
                catch
                {
                    Assert.Fail();
                }
            }
        }
    }
}
